<!--
 Copyright 2025 Google LLC

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<h2 mat-dialog-title class="dialog-title">{{ isEditMode ? 'Editing Tool' : 'Add New Tool' }}</h2>

<mat-dialog-content>
  <ng-container *ngIf="getToolInfo()">
    <div class="tool-info-container">
      <div class="tool-info-header" (click)="toggleToolInfo()">
        <mat-icon class="tool-info-icon">info</mat-icon>
        <div class="tool-info-title">
          <span>Tool Information</span>
        </div>
        <button mat-icon-button class="tool-info-toggle" type="button" aria-label="Toggle tool information">
          <mat-icon>{{ isToolInfoExpanded ? 'expand_less' : 'expand_more' }}</mat-icon>
        </button>
      </div>
      <div class="tool-info-body" [class.expanded]="isToolInfoExpanded">
        <div class="tool-info-content">
          <div class="tool-info-short">{{ getToolInfo()?.shortDescription }}</div>
          <div class="tool-info-detailed">{{ getToolInfo()?.detailedDescription }}</div>
        </div>
        <div class="tool-info-link-container">
          <a [href]="getToolInfo()?.docLink" target="_blank" rel="noopener noreferrer" class="tool-info-link">
            <mat-icon>open_in_new</mat-icon>
            <span>View Official Documentation</span>
          </a>
        </div>
      </div>
    </div>
  </ng-container>

  @if (toolType === 'Function tool') {
  <mat-form-field style="width: 100%;">
    <input
      [(ngModel)]="toolName"
      matInput
      placeholder="Enter full function name"
      (keydown.enter)="addTool()">
  </mat-form-field>
  }

  @if (toolType === 'Built-in tool') {
  <mat-form-field style="width: 100%;">
    <mat-select [(ngModel)]="selectedBuiltInTool" placeholder="Select built-in tool">
      <mat-option *ngFor="let tool of builtInTools" [value]="tool">
        {{ tool }}
      </mat-option>
    </mat-select>
  </mat-form-field>
  }
</mat-dialog-content>

<mat-dialog-actions align="end">
  <button mat-button (click)="cancel()">Cancel</button>
  <button
    mat-button
    cdkFocusInitial
    (click)="addTool()"
    [disabled]="createDisabled()">
    {{ isEditMode ? 'Save' : 'Create' }}
  </button>
</mat-dialog-actions>
